package com.lingnan.club.utils;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lingnan.club.mapper.UserMapper;
import com.lingnan.club.pojo.User;
import com.lingnan.club.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务
 * 重置每周，每月的在线时间
 */
@Component
public class ResetTime {

    @Autowired
    private UserService userService;

    /**
     * 每月最后 1 日 23:30 触发
     */
    @Scheduled(cron = "* 30 23 L * ? ")
    public void resetMonthTime(){
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.set("month_time",0);
        userService.update(wrapper);
    }

    /**
     * 每周日 23:30 触发
     */
    @Scheduled(cron = "* 30 23 * * 7 ")
    public void resetWeekTime(){
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.set("week_time",0);
        userService.update(wrapper);
    }

}
